#!/usr/bin/env python
# coding=utf-8

info_list = ['0', '0', '0']

#取字符串中两个符号之间的内容
def get_item(start_str, end_str, str):
    start = str.find(start_str)
    if start >= 0:
        start += len(start_str)
        end_str = str.find(end_str, start)
        if end_str >= 0:
            return str[start:end_str].strip()

#read file
def read_file():
    #open file
    fo = open("configure", "r")
    print ("file name:", fo.name)

    all_line = fo.readlines()
    for i in range(len(all_line)):
        line = all_line[i].strip()
        if len(line) == 0:
            continue
        elif line[0] == '#':
            continue
        elif line[0] == '[':
            #print("item line: %s" %(line))
            item = get_item('[', ']', line)
            print("item: %s" %(item))
            if item == "SMTP":
                mail_user = all_line[i+1][7:15]
                mail_pass = all_line[i+2][9:19]
                print("mail_user: %s\nmail_pass: %s" %(mail_user, mail_pass))
            elif item == "RECV":
                receivers = all_line[i+1][12:28]
                print("receivers: %s" %(receivers))
        else:
            continue
    
    info_list[0] = mail_user
    info_list[1] = mail_pass
    info_list[2] = receivers

    return info_list

    #close file
    fo.close()
